/**
 * 
 */
package ca.uwo.android.sslconnection;

import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.scheme.PlainSocketFactory;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.SingleClientConnManager;
import org.apache.http.params.HttpParams;

import android.content.Context;

/**
 * @author dantrob (Dennis Antrobus)
 * Extends DefaultHttpClient and uses EasySSLSocketFactory class to circumvent https connection issues without requiring
 * the inclusion of certificates in the app. 
 */
public class WesternHttpClient extends DefaultHttpClient 
{    
	  final Context context;

	  public WesternHttpClient(HttpParams params, Context context)
	  {
	    super(params);
	    this.context = context;     
	  }
	  
	  public WesternHttpClient(HttpParams params){
		  this(params, null);
	  }
	  
	  public WesternHttpClient(Context context){
		  this(null,context);
	  }

	  @Override
	  protected ClientConnectionManager createClientConnectionManager() {
	    SchemeRegistry registry = new SchemeRegistry();
	    registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));

	    // Register for port 443 our SSLSocketFactory with our keystore
	    // to the ConnectionManager
	    registry.register(new Scheme("https", new EasySSLSocketFactory(), 443));

	    return new SingleClientConnManager(getParams(), registry);
	  }
	}